package com.music.glide.load.engine.bitmap_recycle

import com.music.glide.util.Util

abstract class KBaseKeyPool<T : KPoolAble> {

    private val keyPool by lazy { Util.createQueue<T>(MAX_SIZE) }

    fun get(): T {
        return keyPool.poll() ?: create()
    }

    fun offer(key:T) {
        if (keyPool.size < MAX_SIZE) {
            keyPool.offer(key)
        }
    }

    abstract fun create(): T

    companion object {

        const val MAX_SIZE = 20
    }

}